package merisis.util;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.logging.Logger;

public class WordArraySilo implements WordArrayMedia {

	Logger logger = Logger.getLogger(WordArraySilo.class.getName());

	public final byte TRUNK_SCALE = 20;

	public WordArrayTrunk edgeTrunk;

	public WordArraySilo(File home) {
		edgeTrunk = new WordArrayTrunk(home, TRUNK_SCALE);
		try {
			edgeTrunk.open(0);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public long read(long pos) {

		try {
			return select(pos).read(pos);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public ByteBuffer allocate(int numOfWord) {

		return ByteBuffer.allocate(numOfWord << 3);
	}

	public long append(ByteBuffer wordbuf) {

		try {
			return edgeTrunk().append(wordbuf);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	private WordArrayTrunk edgeTrunk() {
		return edgeTrunk;
	}

	private WordArrayTrunk select(long pos) {

		// long file = pos >>> TRUNK_SCALE;
		return edgeTrunk;
	}
}
